package fzdy.controller;

import fzdy.controller.dto.StreetDTO;
import fzdy.entity.DeviceInfo;
import fzdy.entity.Street;
import fzdy.service.IDeviceInfoService;
import fzdy.service.IStreetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping(value = "/sysmanage")
public class StreetController {
    @Autowired
    private IStreetService streetService;
    @Autowired
    private IDeviceInfoService deviceInfoService;

    @RequestMapping(value = "/street/streetData")
    @ResponseBody
    public List streetData() {
        List<Street> list = streetService.getList();
        List<StreetDTO> streetDTOS = new ArrayList<>();
        for (Street street : list) {
            StreetDTO dto = new StreetDTO();
            dto.setId(street.getId());
            dto.setStreetName(street.getStreetName());
            dto.setCenterSpot(street.getLocation());
            dto.setSpotLat(street.getSpotLat());
            dto.setSpotLng(street.getSpotLng());
            streetDTOS.add(dto);
        }
        return streetDTOS;
    }

    @RequestMapping(value = "/device/getmarkerdata")
    @ResponseBody
    public List<DeviceInfo> getmarkerdata() {
        deviceInfoService.mapData();
        return deviceInfoService.getList();
    }
}
